﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Essentials;
using Xamarin.Forms;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.Xaml;

namespace ZXXFAPP.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class WebViewPage : ContentPage
    {
        public WebViewPage()
        {
            InitializeComponent();
            MainWebView.Source = "https://"+ Preferences.Get("SERVER", "168.168.100.125:10000");
            //MainWebView.Source = "https://192.168.3.217:12000";

            MessagingCenter.Subscribe<ScanPage,string>(this, "BarcodeScanResult", (sender, barcode) =>
            {
                // 在这里，你可以使用 JavaScript 与 WebView 交互，将条形码传递给网页
                Trace.WriteLine("barcode aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: " + barcode);
                var script = $"window.receiveAppMsg('{barcode}');";
                MainWebView.EvaluateJavaScriptAsync(script);
            });
        }

    }
}